<template>
  <div class="apply">
    <div class="form">
      <div class="form-item">
        <div class="label">组别：</div>
        <div class="value">
          <el-select size="small" v-model="formData.levelDicCode" placeholder="| 请选择组别">
            <el-option v-for="item in groupOptions" :key="item.code" :label="item.word" :value="item.code">
            </el-option>
          </el-select>
        </div>
      </div>
      <div class="form-item">
        <div class="label">姓名：</div>
        <div class="value">
          <el-input size="small" v-model="formData.userName" placeholder="| 请填写你的真实姓名"></el-input>
        </div>
      </div>
      <div class="form-item">
        <div class="label">手机：</div>
        <div class="value">
          <el-input size="small" v-model="formData.phoneNum" placeholder="| 请填写正确的手机号码"></el-input>
        </div>
      </div>
      <div @click="submitFn" class="form-btn">
        提&nbsp;交
      </div>
    </div>
  </div>
</template>
<script>
import { GetGroups, Login } from '../api/newapi';
export default {
  data () {
    return {
      ruleVisible: false,
      formData: {},
      groupOptions: []
    }
  },
  mounted () {
    GetGroups().then((res) => {
      this.groupOptions = res
      console.log(res);
    }).catch((err) => {
      console.log(err);

    })
  },
  methods: {
    submitFn () {
      let reg = /^1[3456789]\d{9}$/;
      if (!this.formData.levelDicCode) {
        return this.$toast("请选择组别");
      }
      if (!this.formData.userName) {
        return this.$toast("请输入你的真实姓名");
      }
      if (!this.formData.phoneNum) {
        return this.$toast("请输入手机号码");
      }
      if (!reg.test(this.formData.phoneNum)) {
        return this.$toast("请输入正确的手机号码");
      }
      Login(this.formData).then((res) => {
        if (!res.status) {
          localStorage.setItem('userInfo', JSON.stringify({ ...res, levelDicCode: this.formData.levelDicCode }))
          // this.$router.push("/home");
          this.$router.replace("/home");
        } else {
          return this.$toast(res.message);
        }
      }).catch((err) => {
        console.log(err);
      })
    },
  }
}
</script>
<style lang="scss" scoped>
.apply {
  position: relative;
  width: 100%;
  height: 100vh;
  min-height: 743px;
  box-sizing: border-box;
  background: url('../assets/image/apply_bg.png');
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  padding-top: 470px;
  .form {
    padding: 0 64px;
    .form-item {
      display: flex;
      align-items: center;
      height: 34px;
      margin-bottom: 20px;
      .label {
        width: 60px;
        height: 15px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        font-size: 16px;
        color: #333333;
      }
    }
    .form-btn {
      margin: 36px auto 0;
      width: 240px;
      height: 46px;
      line-height: 46px;
      text-align: center;
      background: linear-gradient(
        0deg,
        rgba(1, 115, 211, 0.97),
        rgba(83, 198, 254, 0.97)
      );
      border-radius: 23px;
      font-family: Source Han Sans CN;
      font-weight: 500;
      font-size: 19px;
      color: #ffffff;
      .img {
        width: 100%;
      }
    }
  }
}
</style>
<style lang="scss" >
.el-input {
  width: 100% !important;
  min-width: 180px !important;
}
.el-input__inner {
  border: 1px solid #70d1fe !important;
  border-radius: 0px !important;
}
</style>